package com.mantou.scucorse.core.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.mantou.scucorse.core.entity.User;
import com.mantou.scucorse.utils.ReturnCode;
import com.mantou.scucorse.utils.ReturnContainer;
import com.mantou.scucorse.utils.SystemInfo;

@Controller
@SessionAttributes("userId")
@RequestMapping("/system/")
public class TaskInfoRestApiController {
	@RequestMapping(value="/hibrate/{syskey}",method = RequestMethod.GET)
	public ResponseEntity<ReturnContainer<Integer>>  hibtate(@PathVariable String syskey){
		if(!syskey.equals(SystemInfo.syskey)){
			return new ResponseEntity<ReturnContainer<Integer>>(new ReturnContainer<Integer>(0,"key not correct",0), HttpStatus.OK);
		}
		SystemInfo.taskHibrate = true;
		return new ResponseEntity<ReturnContainer<Integer>>(new ReturnContainer<Integer>(0,"success",1), HttpStatus.OK);
	}
	
	@RequestMapping(value="/wakeup/{syskey}",method = RequestMethod.GET)
	public ResponseEntity<ReturnContainer<Integer>>  wakeup(@PathVariable String syskey){
		if(!syskey.equals(SystemInfo.syskey)){
			return new ResponseEntity<ReturnContainer<Integer>>(new ReturnContainer<Integer>(0,"key not correct",0), HttpStatus.OK);
		}
		SystemInfo.taskHibrate = false;
		return new ResponseEntity<ReturnContainer<Integer>>(new ReturnContainer<Integer>(0,"success",1), HttpStatus.OK);
	}
	@RequestMapping(value="/changekey/{syskey}/{newkey}",method = RequestMethod.GET)
	public ResponseEntity<ReturnContainer<Integer>>  changekey(@PathVariable String syskey,@PathVariable String newkey){
		if(!syskey.equals(SystemInfo.syskey)){
			return new ResponseEntity<ReturnContainer<Integer>>(new ReturnContainer<Integer>(ReturnCode.KEYNOTCORRECT.getStatus()
					,ReturnCode.KEYNOTCORRECT.getDescription(),null), HttpStatus.OK);
		}
		SystemInfo.syskey = newkey;
		return new ResponseEntity<ReturnContainer<Integer>>(new ReturnContainer<Integer>(ReturnCode.OK.getStatus(),ReturnCode.OK.getDescription(),null), HttpStatus.OK);
	}
}
